<?

/*
*
*   Excalibur Content Management System
*   Copyright © 2008 Egor "Sontan" Kuryanovich
*
*   Based on Explay Engine v2.0 by Golovdinov Alexander
*
*   Official site: www.excms.ru
*   Contact e-mail: support@excms.ru
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
*/

if ($EXCMS != 'work') {
	header ('Location: ../../index.php');
	exit;
}

$number = 30;
$start = 0;
if (isset($_GET['page']) && $_GET['page'] != "0") 
	$start = (intval ($_GET['page']) - 1) * $number;


past_navblock (array (
							array ('Написать статью', '/my_articles/add/', 'cat', 'add'),
							array ('Поиск по тегам', '/articles/tags/', 'cat', 'tags'),
							array ('Комментарии', '/art_comments/', 'name', 'art_comments'),
							array ('TOP блогов', '/top/', 'name', 'top'),
							
					)
					);


$get = $db->query ('SELECT ac.cat_name, ac.cat_header, ac.cat_rating, ac.cat_users, SUM(a.art_rating) AS rating, COUNT(*) AS count
	FROM '.DB_PEREFIX.'_art_category AS ac
	JOIN '.DB_PEREFIX."_articles AS a ON ( a.art_category = ac.cat_name)
	WHERE a.art_like_page = 'no'
	GROUP BY ac.cat_name
	ORDER BY ac.cat_rating DESC	 LIMIT $start, $number;");

$list = '';	

while ($blog = $db->fetch_array ($get)) 
{
	//list ($name, $header, $rating, $users, $cnt)
	
	$template->set_var ('{NAME}', $blog['cat_name']);
	$template->set_var ('{HEADER}', $blog['cat_header']);
	$template->set_var ('{USERS}', $blog['cat_users']);
	$template->set_var ('{ARTS}', $blog['count']);
	$template->set_var ('{RATING}', $blog['rating']);	
	$template->set_var ('{KARMA}', number_format ($blog['cat_rating'], 2, ',', ''));
	
	$list .= $template->display ('articles/blog_list.tpl');	
}

$template->set_var ('{LIST}', $list);
print $template->display ('articles/blog_top.tpl');	

$count = $db->fetch_row ($db->query ('SELECT count(*) FROM '.DB_PEREFIX.'_art_category'));
if ($count[0] > $number) print past_pages($start, $number, $count[0], '/top/');
